requireJS(['constant', 'site', 'handlebars'], function (Constant, site, Handlebars) {


    var initData = function () {
        site.send({
            url: "manager/selectStatus.do",
            //async:false
            data: {},
            callback: function (data) {
                var list = JSON.parse(data)
                var template = Handlebars.compile($("#state_content_tpl").html())
                var html = template(list)
                $("#state_content").html(html)

                onBindFun();
            }

        })

    }
    initData();
function onBindFun() {
    // 编辑状态弹框
    $(".tabedit").click(function () {
        $(".state_winBox_id").text($(this).data("id"));
        $(".state_winBox_name").val($(this).data("name"))
        $(".state_winBox_content").val($(this).data("content"))
        $(".winBox_edit").toggle();
        textareaFn();
    })

}


    // 提交编辑
    $(".deleBtn").click(function () {
        commitFun();
    })


// 字数限制初始化
    var textareaFn = function () {
        var textval = $(".state_winBox_content").val().length//text框的val值
        var textmaxLength = $(".state_winBox_content").attr('maxLength');
        var zishuxianzhi = textmaxLength - textval;
        $(".zishu").html("<i id=\"zishuxians\">" + zishuxianzhi + "</i>/" + $(".state_winBox_content").attr('maxLength') + "字");
    }
    // 字数限制的键盘up绑定
    $(".state_winBox_content").on('keyup', function () {
        var textval = $(".state_winBox_content").val()
        $("#zishuxians").text($(".state_winBox_content").attr('maxLength') - textval.length)

    })

    function commitFun() {
        site.send({
            url: "manager/updateStatus.do",
            //async:false
            data: {
                id: $('.state_winBox_id').text(),
                s_name: $('.state_winBox_name').val(),
                s_describe: $('.state_winBox_content').val()
            },
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == 1) {
                    $(".winBox_edit").toggle();
                    initData();
                    Constant.fn.Message('T',list.msg);
                }else{
                    Constant.fn.Message('F',list.msg);
                }

            }

        })
    }

})